
#######通用Makefile模板########


.PHONY : all
	
# SRC = Main.cpp Socket_TCPIP.cpp Socket_Base.cpp
# 找出扩展名是cpp的，放进OBJS_SRC
# CODE_SRC = $(foreach x, $(VPATH), $(notdir $(wildcard $(x)/*.cpp)))
# MAIN_SRC = $(foreach x, $(MPATH), $(notdir $(wildcard $(x)/*.cpp)))

# object文件,只是改变文件名
# CODE_OBJS = $(CODE_SRC:.cpp=.o)
# MAIN_OBJS = $(MAIN_SRC:.cpp=.o)
cc := g++
inclu := -I/usr/include/
# 链接库
linkp := 
# 编译选项
flags := -ansi -g -Wall
# .o文件存放路径
path_o := ./comp
# 生成可执行文件名
target = serpro

define pick_pat
exd_dires := ./build ./nbproject ./dist ./.svn
files := $(wildcard $(1)/*)
dires := 
# 可以wildcard开的就是文件夹，定义为DIRES，添加进DIRES里
$$(foreach e, $$(files), $$(if $$(wildcard $$(e)/*), $$(eval dires := $$(dires) $$(e))))
# 把集合里的是路径的都filter-out掉，然后把文件里类型后缀是$(2)(目前是%.cpp)都筛选出来，也就是去掉不是cpp后缀的
files := $$(filter $(2), $$(filter-out $$(dires),$$(files)))
# 去掉不扫描的路径 上面定义的那些
dires := $$(filter-out $$(exd_dires),$$(dires))
all_files := $$(all_files) $$(files)
$$(foreach e,$$(dires),$$(eval $$(call pick_pat, $$(e), $(2))))
endef


define comp_objs
    @for _e in $1; do \
	echo $(cc) $(linkp) $(inclu) $(flags) -c $$_e; \
	$(cc) $(linkp) $(inclu) $(flags) -c $$_e; \
    done
endef

define comp_targ
    $(cc) $(linkp) -o $1 $2
endef

define moveto
    mv $1 $2
endef

all : CMP_targ
	@echo 123
	
# object文件,只是改变文件名


CMP_targ : CMP_objs
	$(eval $(call pick_pat, ., %.o))
	$(eval all_objs := $(filter-out %.cpp, $(all_files)))
	@echo $(all_objs)
	$(call comp_targ, $(target), $(all_objs))

CMP_objs :
	$(eval $(call pick_pat, ., %.cpp))
	@echo $(dires)
	@echo "=="
	@echo $(all_files)
	$(call comp_objs, $(all_files))
	
.SUFFIXES:.cpp
%.o:%.cpp
	$(cc) $(linkp) $(inclu) $(flags) -c $< -o $(path_o)

# 定义清理函数

clean:
	rm $(all_objs)
	
eee:=./main.cpp
tfile := $(patsubst %.cpp, %.o, $(eee))
test:
	
	@echo $(tfile)
	
